package jjn.daily;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author Jiang Jining
 * @since 2023-07-27 22:57
 */
public class LeetCode2500 {
    public int deleteGreatestValue(int[][] grid) {
        if (grid.length == 0 || grid[0].length == 0) {
            return 0;
        }
        for (int[] ints : grid) {
            Arrays.sort(ints);
        }
        int result = 0;
        for (int i = grid[0].length - 1; i >= 0; i--) {
            int maxForRow = 0;
            for (int[] ints : grid) {
                maxForRow = Math.max(ints[i], maxForRow);
            }
            result += maxForRow;
        }
        return result;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int height = scanner.nextInt();
        int width = scanner.nextInt();
        int[][] grid = new int[height][width];
        for (int i = 0; i < height; i++) {
            for (int j = 0; j < width; j++) {
                grid[i][j] = scanner.nextInt();
            }
        }
        int greatestValue = new LeetCode2500().deleteGreatestValue(grid);
        System.out.println(greatestValue);
    }
}
